<extend name="Layout/index" />
<block name="resource">
    <link rel="stylesheet" href="__PUBLIC__/my.css" />
</block>
<block name="breadcrumb-01">
    <li>
        <i class="icon-home home-icon"></i>
        <a href="<{:U('Index/index')}>">首页</a>
    </li>
    <li class="active">前台用户管理</li>
</block>
<block name="search">
<div class="nav-search" id="nav-search">
    <form class="form-search" action="<{:U('User/index')}>" method="get">
        <span class="input-icon" >
            <input type="text" placeholder="请输入用户名" class="nav-search-input" id="nav-search-input" autocomplete="off" name="name" />
            <i class="icon-search nav-search-icon"></i>
        </span>
    </form>
</div><!-- #nav-search -->
</block>
<block name="breadcrumb-02">
    <h1>
        前台用户管理
        <small>
            <i class="icon-double-angle-right"></i>
             用户信息
        </small>
    </h1>
    <hr>
    <button class="btn-xs" id="add_user">添加用户</button>
    <div>
        <!-- 添加用户 -->
        <div class="add_user form-group" id="box_add_user">
            <button class=" btn-xs" id="close_add"><h6>X</h6></button>

            <form action="add" method="post">
              <div class="form-group">
                <label for="user_name">用户名：</label>
                <input type="text" class="form-control" id="user_name" placeholder="用户名" name="name">
              </div>

              <div class="form-group">
                <label for="password">密码：</label>
                <input type="password" class="form-control" id="password" placeholder="密码" name="password">
              </div>

              <div class="form-group">
                <label for="user_nickname">昵称：</label>
                <input type="text" class="form-control" id="user_nickname" placeholder="昵称" name="nickname">
              </div>

              <div class="form-group">
                <label>性别：</label>
                <input type="radio" name="sex" value="1" checked>男 <input type="radio" name="sex" value="2">女
              </div>

              <div class="form-group">
                    <label >状态：</label>
                    <input type="radio" name="status" value="0" checked>正常
                    <input type="radio" name="status" value="1">禁言
                    <input type="radio" name="status" value="0">封号
              </div>

              <div class="form-group">
                <label for="phone">手机：</label>
                <input type="text" class="form-control" id="phone" placeholder="手机" name="phone">
              </div>

              <div class="form-group">
                <label for="email">邮箱：</label>
                <input type="email" class="form-control" id="email" placeholder="邮箱" name="email">
              </div>

              <div class="form-group">
                <label for="signature">个性签名：</label>
                <input type="text" class="form-control" id="signature" placeholder="个性签名" name="signature">
              </div>
              <button type="submit" class=" btn-info btn-sm">添加</button>
            </form>
        
        </div><!-- /添加用户 -->
        <!-- 编辑用户 -->
        <div class="edit_user form-group" id="box_edit_user" >
            <button class=" btn-xs" id="close_edit"><h6>X</h6></button>

            <form action="update" method="post" name="edit_info">
              <div class="form-group">
                <label for="user_name">用户名：</label>
                <input type="text" class="form-control" id="user_name" placeholder="用户名" name="name">
              </div>

              <div class="form-group">
                <label for="password">密码：</label>
                <input type="password" class="form-control" id="password" placeholder="密码不修改请勿填写" name="password" value="">
              </div>

              <div class="form-group">
                <label for="user_nickname">昵称：</label>
                <input type="text" class="form-control" id="user_nickname" placeholder="昵称" name="nickname">
              </div>

              <div class="form-group">
                <label>性别：</label>
                <input type="radio" name="sex" value="1" id="sex_man">男 <input type="radio" name="sex" value="2" id="sex_woman">女
              </div>

              <div class="form-group">
                    <label >状态：</label>
                    <input type="radio" name="status" value="0" id="status_normal" >正常
                    <input type="radio" name="status" value="1" id="status_nospeak">禁言
                    <input type="radio" name="status" value="0" id="status_kill">封号
              </div>

              <div class="form-group">
                <label for="phone">手机：</label>
                <input type="text" class="form-control" id="phone" placeholder="手机" name="phone">
              </div>

              <div class="form-group">
                <label for="email">邮箱：</label>
                <input type="email" class="form-control" id="email" placeholder="邮箱" name="email">
              </div>

              <div class="form-group">
                <label for="signature">个性签名：</label>
                <input type="text" class="form-control" id="signature" placeholder="个性签名" name="signature">
              </div>
              <input type="hidden" name="id" value="">
              <button type="submit" class=" btn-info btn-sm" button="edit()">修改</button>
            </form>
        </div><!-- /编辑用户 -->

    <table class="table table-striped table-bordered table-hover">
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>昵称</th>
            <th>性别</th>
            <th>手机</th>
            <th>邮箱</th>
            <th>金币</th>
            <th>经验</th>
            <th>状态</th>
            <th>注册时间</th>
            <th>操作</th>
        </tr>
        <if condition="$list eq 0">
        <tr>
            <th colspan="11" class="center h3">暂无数据</th>
        </tr>
        <else />
        <volist name="list" id="vo">
            <tr>
                <td><{$vo.id}></td>
                <td><a href="/admin/user/info?id=<{$vo.id}>"><{$vo['name']}></a></td>
                <td><{$vo['nickname']}></td>
                <td><if condition="$vo['sex'] eq 1">男<else />女</if></td>
                <td><{$vo['phone']}></td>
                <td><{$vo['email']}></td>
                <td><{$vo['gold']}></td>
                <td><{$vo['exp']}></td>
                <td>
                    <if condition="$vo['status'] eq 0"><span class="text-success blod"><strong>正常</strong></span>
                    <elseif condition="$vo['status'] eq 1" /><span class="text-warning blod"><strong>禁言</strong></span>
                    <else /><span class="text-danger blod"><strong>封号</strong></span>
                    </if>
                </td>
                <td><{$vo['time']}></td>
                <td><button class=" btn-xs " onclick="normal(<{$vo.id}>,this)">解禁</button> <button class=" btn-xs btn-info" onclick="nospeak(<{$vo.id}>,this)">禁言</button> <button class="btn-xs btn-warning" onclick="kill(<{$vo.id}>,this)">封号</button> <button class=" btn-xs btn-success edit"  onclick="edit(<{$vo.id}>,this)">修改</button> <button class=" btn-xs btn-danger" onclick = "del(<{$vo.id}>,this)">删除</button></td>
            </tr>
        </volist>
        </if>
    </table>
    <div class="green-black"><{$page}><div/>
</block>

<block name="jquery">
    <script>
        $('#add_user').click(function(){$('#box_add_user').slideToggle();})
        $('#close_add').click(function(){$('#box_add_user').slideUp();})
        $('#close_edit').click(function(){$('#box_edit_user').slideUp();})

        /**
         * [nospeak 编辑传值函数]
         * @param  {[type]} id  [用户id]
         * @param  {[type]} obj [按钮对象]
         */
        function edit(id,obj){
            $('#box_edit_user').slideDown();
            var tr = $(obj).parent().parent().children();
            $.ajax({
                type:'get',
                url:'<{:U('Admin/User/edit')}>',
                data:{'id':id},
                success:function(data){
                    console.log(data);
                    edit_info.name.value = data.name;
                    edit_info.password.value = '';
                    if (data.sex == 1) {$('#sex_man').attr('checked','1');};
                    if (data.sex == 2) {$('#sex_woman').attr('checked','1');};
                    if (data.status == 0) {$('#status_normal').attr('checked','1');};
                    if (data.status == 1) {$('#status_nospeak').attr('checked','1');};
                    if (data.status == 2) {$('#status_kill').attr('checked','1');};

                    edit_info.nickname.value = data.nickname;
                    edit_info.phone.value = data.phone;
                    edit_info.email.value = data.email;
                    edit_info.id.value = data.uid;
                    edit_info.signature.value = data.signature;
                }
            });
        }

        
        /**
         * [nospeak 禁言函数]
         * @param  {[type]} id  [用户id]
         * @param  {[type]} obj [按钮对象]
         */
        function nospeak(id,obj){
            var tr = $(obj).parent().parent().children();
            $.ajax({
                type:'get',
                url:'<{:U('Admin/User/nospeak')}>',
                data:{'id':id},
                success:function(data){
                tr[8].innerHTML = '<span class="text-warning blod"><strong>禁言</strong></span>';
                }
            });
        }

        /**
         * [nospeak 删除函数]
         * @param  {[type]} id  [用户id]
         * @param  {[type]} obj [按钮对象]
         */
        function del(id,obj){
            var tr = $(obj).parent().parent();
            $.ajax({
                type:'get',
                url:'<{:U('Admin/User/del')}>',
                data:{'id':id},
                success:function(data){
                $(tr).remove();
                }
            });
        }
        /**
         * [nospeak 解禁函数]
         * @param  {[type]} id  [用户id]
         * @param  {[type]} obj [按钮对象]
         */
        function normal(id,obj){
            var tr = $(obj).parent().parent().children();
            $.ajax({
                type:'get',
                url:'<{:U('Admin/User/normal')}>',
                data:{'id':id},
                success:function(data){
                tr[8].innerHTML = '<span class="text-success blod"><strong>正常</strong></span>';
                }
            });
        }

        /**
         * [nospeak 封号函数]
         * @param  {[type]} id  [用户id]
         * @param  {[type]} obj [按钮对象]
         */
        function kill(id,obj){
            var tr = $(obj).parent().parent().children();
            $.ajax({
                type:'get',
                url:'<{:U('Admin/User/kill')}>',
                data:{'id':id},
                success:function(data){
                tr[8].innerHTML = '<span class="text-danger blod"><strong>封号</strong></span>';
                }
            });
        }
    </script>
</block>